<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./02 商品.css" />
  </head>
  <body>
    <div id="app">
      <!-- 商品规格列表 -->
      <div class="goods" v-for="(good,gIndex) in goodsList" :key="good.id">
        <div class="title">{{good.title}}:</div>
        <ul class="type-list">
          <li class="type" 
          v-for="(type,tIndex) in good.typeList" 
          :class="{active: good.currentIndex === tIndex}"
          @click="onFilter(gIndex,tIndex)"
          >{{type}}</li>
 
        </ul>
      </div>
     

      <!-- 商品选择结果 -->
      <div class="choose-type">
        <div>已选条件:</div>

        <span v-if="filterGoods.length<=0" class="no-goods">暂时没有选择过滤条件</span>
        <ul v-else class="filter-list">
          <li v-for="good in filterGoods">
            {{good[1]}}
            <span class="delete-goods" @click="goodsList[good[0]].currentIndex=0">x</span>
          </li>
        </ul>
      </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
    <script>
      var goodsList = [
        {
          title: "上装",
          typeList: [
            "全部",
            "针织衫",
            "毛呢外套",
            "T恤",
            "羽绒服",
            "棉衣",
            "卫衣",
            "风衣",
          ],
          id: 1,
        
        },
        {
          title: "裤装",
          typeList: [
            "全部",
            "牛仔裤",
            "小脚/铅笔裤",
            "休闲裤",
            "打底裤",
            "哈伦裤",
          ],
          id: 2,
        },
        {
          title: "裙装",
          typeList: [
            "全部", 
            "连衣裙", 
            "半身裙", 
            "长袖连衣裙", 
            "中长款连衣裙"],
          id: 3,
        },
      ];
        var vm = new Vue({
            el: "#app",
            data: {
              goodsList
            },
            methods: {
              onFilter(gIndex,tIndex){
                this.goodsList[gIndex].currentIndex = tIndex;
              }

            },
            computed: {
              filterGoods(){
                return this.goodsList.map((good, index) =>[ index, good.typeList[good.currentIndex]]).filter(good => good[1] !== '全部')
              }
            }
        })

        vm.goodsList.forEach(good =>vm.$set(good,"currentIndex",0))
    </script>
  </body>
</html>
